package com.sundi.ecmarket.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sundi.ecmarket.config.ExcelBean;
import com.sundi.ecmarket.config.ExcelUtils;
import com.sundi.ecmarket.dto.BrandDto;
import com.sundi.ecmarket.dto.CategoryDto;
import com.sundi.ecmarket.entity.EcBrand;
import com.sundi.ecmarket.entity.EcCategory;
import com.sundi.ecmarket.mapper.EcCategoryMapper;
import com.sundi.ecmarket.service.IEcCategoryService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sundi.ecmarket.vo.CategoryVo;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 类目表 服务实现类
 * </p>
 *
 * @author Mht
 * @since 2020-02-23
 */
@Service
public class EcCategoryServiceImpl extends ServiceImpl<EcCategoryMapper, EcCategory> implements IEcCategoryService {

    @Override
    public List<CategoryVo> selectCateList(CategoryDto categoryDto) {
        return this.baseMapper.selectCateList(categoryDto);
    }

    @Override
    public boolean deleteByCate(Integer id) {
        return this.baseMapper.deleteByCate(id);
    }

    @Override
    public List<EcCategory> selectParentList(CategoryDto categoryDto) {
        return this.baseMapper.selectParentList(categoryDto);
    }

    @Override
    public int selectMaxId() {
        return this.baseMapper.selectMaxId();
    }

    @Override
    public XSSFWorkbook downLoadGoodsExcel(CategoryDto categoryDto) throws Exception {
        PageHelper.startPage(categoryDto.getPageNo(),categoryDto.getPageSize());
        Wrapper wrapper = new EntityWrapper();

        List<EcCategory> list = this.selectList(wrapper);
        PageInfo<EcCategory> pageInfo = new PageInfo(list);
        Map<Integer,List<ExcelBean>> map = new HashMap<Integer,List<ExcelBean>>();
        List<ExcelBean> excelBeans = new ArrayList<>();
        excelBeans.add(new ExcelBean("id","id",0));
        excelBeans.add(new ExcelBean("类目名称","name",0));
        excelBeans.add(new ExcelBean("类目关键字，以JSON数组格式","keywords",0));
        excelBeans.add(new ExcelBean("类目广告语介绍","desc",0));
        excelBeans.add(new ExcelBean("父类目ID","pid",0));
        excelBeans.add(new ExcelBean("类目图标","iconUrl",0));
        excelBeans.add(new ExcelBean("类目图片","picUrl",0));
        excelBeans.add(new ExcelBean("排名","level",0));
        excelBeans.add(new ExcelBean("排序","sortOrder",0));

        map.put(0,excelBeans);

        return ExcelUtils.createExcelFile(EcCategory.class,pageInfo.getList(),map,"商铺列表");
    }
}
